﻿using System;
using System.Linq;
using System.Collections.Generic;

using Microsoft.WindowsMobile.PocketOutlook;

namespace iPhoneUI.Widgets
{
    class AppointmentEqualityComparer : IEqualityComparer<Appointment>
    {
        public AppointmentEqualityComparer()
        {
        }

        public bool Equals(Appointment a, Appointment b)
        {
            // if both are null they are the same
            if (a == null && b == null)
                return true;

            // one is null but the other isn't - they are different
            if (a == null || b == null)
                return false;

            // compare hashcodes
            return GetHashCode(a) == GetHashCode(b);
        }

        public int GetHashCode(Appointment obj)
        {
            unchecked
            {
                // identity is based on start, end, subject and location
                return obj.Start.GetHashCode() ^ obj.End.GetHashCode() ^ obj.Subject.GetHashCode() ^ obj.Location.GetHashCode();
            }
        }
    }
}